package com.iakuil.app.api.task;

import com.iakuil.app.common.core.util.DateUtils;
import lombok.extern.slf4j.Slf4j;
import net.javacrumbs.shedlock.spring.annotation.SchedulerLock;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

/**
 * 定时任务示例
 *
 * <p>需要配置开关app.scheduling.enabled=true
 *
 * @author Kai
 */
@Slf4j
@Component
public class DemoJob {
    /**
     * 每分钟执行一次
     */
    @Scheduled(cron = "0 */1 * * * ?")
    @SchedulerLock(name = "demoTaskLock", lockAtMostFor = "3000", lockAtLeastFor = "1000")
    public void doSomething1() {
        log.info("====================> 定时任务（一）抢到锁啦！时间：" + DateUtils.now());

    }

    /**
     * 每分钟执行一次
     */
    @Scheduled(cron = "0 */1 * * * ?")
    @SchedulerLock(name = "demoTaskLock", lockAtMostFor = "3000", lockAtLeastFor = "1000")
    public void doSomething2() {
        log.info("====================> 定时任务（二）抢到锁啦！时间：" + DateUtils.now());

    }
}
